package com.ruoyi.project.order.controller;

import cn.mabach.order.entity.OrderSettingEntity;
import cn.mabach.result.PageResult;
import cn.mabach.result.RS;
import com.ruoyi.project.order.feign.OrderSettingServiceFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 订单设置表
 *
 * @author chenshun
 * @email 176468159@qq.com
 * @date 2020-01-02 23:46:11
 */
@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {
    @Autowired
    private OrderSettingServiceFeign orderSettingService;



    /**
        * 分页列表
        */
    @GetMapping(value = "/list")
    @PreAuthorize("@ss.hasPermi('sms:orderSetting:read')")
    public RS<PageResult<OrderSettingEntity>> getList(@RequestParam(value = "keyword", required = false) String keyword,
                                                      @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
                                                      @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) {

        RS<PageResult<OrderSettingEntity>> pageResultRS = orderSettingService.queryPage(keyword, pageNum, pageSize);

        return pageResultRS;
    }



    /**
     * 根据ID获取信息
     */

    @GetMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPermi('sms:orderSetting:read')")
    public RS<OrderSettingEntity> getItem(@PathVariable("id") Long id) {
        return orderSettingService.getByIdE(id);
    }





    /**
     * 根据id保存
     */
    @PostMapping(value = "/create")
    @PreAuthorize("@ss.hasPermi('sms:orderSetting:create')")
    public RS create(@RequestBody OrderSettingEntity orderSettingEntity) {

        RS rs = orderSettingService.saveE(orderSettingEntity);

        return rs;
    }



    /**
     * 根据id修改
     */
    @PostMapping(value = "/update/{id}")
    @PreAuthorize("@ss.hasPermi('sms:orderSetting:update')")
    public RS update(@PathVariable("id") Long id,
                     @Validated @RequestBody OrderSettingEntity entity,
                     BindingResult result) {
        entity.setId(id);
        RS rs = orderSettingService.updateByIdE(entity);

        return rs;
    }

    /**
       * 根据id集合删除
       */
    @PostMapping(value = "/delete")
    @PreAuthorize("@ss.hasPermi('sms:orderSetting:delete')")
    public RS deleteBatch(@RequestParam("ids") List<Long> ids) {
        RS rs = orderSettingService.removeByIdsE(ids);
        return rs;
    }

    /**
         * 根据id删除
         */
    @RequestMapping(value = "/delete/{id}", method = RequestMethod.POST)
    @PreAuthorize("@ss.hasPermi('sms:orderSetting:delete')")
    public RS removeByIdE(@PathVariable Long id) {

        return orderSettingService.removeByIdE(id);

    }


}
